From 93fab6a9d4ad498128144570907652d145d5d623 Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Sat, 22 Aug 2020 05:56:53 -0600 Subject: [PATCH] Migrate some RegExs to QRegularExpression. (#632) QRegExp will be/is deprecated. --- exif.cc | 69 +++++++++++++++++++++++++++++------------------------- pcx.cc | 37 +++++++++++++++++++++-------- xcsv.cc | 72 ++++++++++++++++++++++++++++----------------------------- 3 files changed, 100 insertions(+), 78 deletions(-) diff --git a/exif.cc b/exif.cc index 2164151dc..d2f71a7f5 100644 --- a/exif.cc +++ b/exif.cc @@ -35,34 +35,37 @@ */ #include "defs.h" -#include "garmin_tables.h" // for gt_lookup_datum_index -#include "gbfile.h" // for gbfile, gbfclose, gbfcopyfrom, gbfseek, gbfwrite, gbfopen_be, gbftell, gbfputuint16, gbfputuint32, gbfgetuint16, gbfgetuint32, gbfread, gbfrewind, gbfgetflt -#include "jeeps/gpsmath.h" // for GPS_Math_WGS84_To_Known_Datum_M -#include "src/core/datetime.h" // for DateTime -#include // for QByteArray -#include // for QDate -#include // for QDateTime -#include // for QFile -#include // for QFileInfo -#include // for QList<>::iterator, QList -#include // for QPair -#include // for QRegExp -#include // for QString -#include // for QTextCodec -#include // for QTime -#include // for QVariant -#include // for QVector -#include // for UTC, ISODate -#include // for qPrintable -#include // for sort, min -#include // for assert -#include // for isprint, isspace -#include // for DBL_EPSILON -#include // for fabs, modf, copysign, round, fmax -#include // for int32_t, int16_t, uint16_t, uint32_t, uint8_t, INT32_MAX -#include // for printf, snprintf, SEEK_SET, SEEK_CUR -#include // for labs, atoi -#include // for strrchr, memcmp, strchr, strlen +#include "garmin_tables.h" // for gt_lookup_datum_index +#include "gbfile.h" // for gbfputuint32, gbfputuint16, gbfgetuint16, gbfgetuint32, gbfile, gbfseek, gbftell, gbfclose, gbfcopyfrom, gbfwrite, gbfopen_be, gbfread, gbfrewind, gbfgetflt, gbfgetint16, gbfopen, gbfputc, gbfputflt, gbsize_t, gbfeof, gbfgetdbl, gbfputdbl, gbfile... +#include "jeeps/gpsmath.h" // for GPS_Math_WGS84_To_Known_Datum_M +#include "src/core/datetime.h" // for DateTime + +#include // for QByteArray +#include // for QDate +#include // for QDateTime +#include // for QFile +#include // for QFileInfo +#include // for QList<>::iterator, QList +#include // for QPair +#include // for QRegularExpression +#include // for QRegularExpressionMatch +#include // for QString +#include // for QTextCodec +#include // for QTime +#include // for QVariant +#include // for QVector +#include // for UTC, ISODate +#include // for qSwap, qPrintable, qint64 + +#include // for sort, min +#include // for assert +#include // for isprint, isspace +#include // for DBL_EPSILON +#include // for fabs, modf, copysign, round, fmax +#include // for uint32_t, int32_t, uint16_t, uint8_t, int16_t, INT32_MAX +#include // for printf, SEEK_SET, snprintf, SEEK_CUR +#include // for labs, atoi +#include // for memcmp, strlen #define MYNAME "exif" @@ -773,11 +776,13 @@ exif_get_exif_time(ExifApp* app) if (offset_tag) { char* time_tag = exif_read_str(offset_tag); // string should be +HH:MM or -HH:MM - QRegExp re("([+-])(\\d{2})(?::)(\\d{2})"); - if (re.exactMatch(time_tag)) { + const QRegularExpression re(R"(^([+-])(\d{2}):(\d{2})$)"); + assert(re.isValid()); + QRegularExpressionMatch match = re.match(time_tag); + if (match.hasMatch()) { // Correct the date time by supplying the offset from UTC. - int offset_hours = re.cap(1).append(re.cap(2)).toInt(); - int offset_mins = re.cap(1).append(re.cap(3)).toInt(); + int offset_hours = match.captured(1).append(match.captured(2)).toInt(); + int offset_mins = match.captured(1).append(match.captured(3)).toInt(); res.setOffsetFromUtc(((offset_hours * 60) + offset_mins) * 60); } } diff --git a/pcx.cc b/pcx.cc index 0ced2de88..cf5dd7839 100644 --- a/pcx.cc +++ b/pcx.cc @@ -19,14 +19,30 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include // for fabs +#include // for atoi +#include // for strstr, strncmp + +#include // for operator==, QChar +#include // for QCharRef +#include // for QDate +#include // for QDateTime +#include // for QList +#include // for QRegularExpression +#include // for QString, QString::KeepEmptyParts, QString::SectionSkipEmpty +#include // for QStringList +#include // for QStringRef +#include // for QTime +#include // for QVector +#include // for CaseInsensitive, UTC + #include "defs.h" -#include "cet_util.h" -#include "csv_util.h" -#include "garmin_tables.h" -#include -#include -#include -#include +#include "cet_util.h" // for cet_convert_init +#include "csv_util.h" // for human_to_dec +#include "garmin_tables.h" // for gt_find_icon_number_from_desc, PCX, gt_find_desc_from_icon_number +#include "gbfile.h" // for gbfprintf, gbfclose, gbfopen, gbfgetstr, gbfile +#include "src/core/datetime.h" // for DateTime + static gbfile* file_in, *file_out; static short_handle mkshort_handle; @@ -71,7 +87,7 @@ static void wr_deinit() { // Find the first token in string |in| when there may be leading whitespace. // These files have weird mixtures of spaces and tabs. static QString FirstTokenAt(const QString& in, int index) { - static const QRegExp sep("\\s+"); + static const QRegularExpression sep(QRegularExpression(R"(\s+)")); return in.mid(index, -1).section(sep, 0, 0, QString::SectionSkipEmpty); } @@ -104,6 +120,7 @@ static void data_read() { read_as_degrees = 0; int points = 0; + const QRegularExpression sep(QRegularExpression(R"(\s+)")); // Each line is both |buff| as a C string and |line| as a QString. while ((buff = gbfgetstr(file_in))) { @@ -116,7 +133,7 @@ static void data_read() { switch (ibuf[0]) { case 'W': { QStringList tokens = - line.split(QRegExp("\\s+"), QString::KeepEmptyParts); + line.split(sep, QString::KeepEmptyParts); if (tokens.size() < 6) { fatal(MYNAME ": Unable to parse waypoint, not all required columns " @@ -216,7 +233,7 @@ static void data_read() { break; case 'T': { QStringList tokens = - line.split(QRegExp("\\s+"), QString::KeepEmptyParts); + line.split(sep, QString::KeepEmptyParts); if (tokens.size() < 6) { fatal(MYNAME ": Unable to parse trackpoint, not all required columns " diff --git a/xcsv.cc b/xcsv.cc index babc01d31..9b3907292 100644 --- a/xcsv.cc +++ b/xcsv.cc @@ -23,42 +23,42 @@ */ -#include // for assert -#include // for isdigit, tolower -#include // for fabs, pow -#include // for snprintf, sscanf -#include // for atof, atoi, strtod, atol -#include // for strlen, strncmp, strcmp, strncpy, memset -#include // for gmtime, localtime, mktime, strftime - -#include // for QByteArray -#include // for QChar -#include // for QCharRef -#include // for QDate -#include // for QDateTime -#include // for QHash -#include // for operator|, QIODevice::ReadOnly, QIODevice::Text, QIODevice::WriteOnly -#include // for QList -#include // for QRegExp -#include // for QString, operator+, operator==, QByteArray::append -#include // for QStringList -#include // for QTextStream -#include // for QTime -#include // for qAsConst, QAddConst<>::Type, qPrintable +#include // for assert +#include // for isdigit, tolower +#include // for fabs, pow +#include // for snprintf, sscanf +#include // for atof, atoi, strtod +#include // for strlen, strncmp, strcmp, memset +#include // for gmtime, localtime, time_t, mktime, strftime + +#include // for QByteArray +#include // for QChar +#include // for QDate +#include // for QDateTime +#include // for QDebug +#include // for QHash +#include // for QIODevice, operator|, QIODevice::ReadOnly, QIODevice::Text, QIODevice::WriteOnly +#include // for QList +#include // for QRegularExpression +#include // for QString, operator+, operator== +#include // for QStringList +#include // for QTextStream +#include // for qAsConst, qPrintable #include "defs.h" -#include "csv_util.h" // for csv_stringtrim, dec_to_human, csv_stringclean, human_to_dec, ddmmdir_to_degrees, dec_to_intdeg, decdir_to_dec, intdeg_to_dec, csv_linesplit -#include "garmin_fs.h" // for garmin_fs_t, garmin_fs_flags_t, GMSD_FIND, GMSD_GET, GMSD_SET, garmin_fs_alloc -#include "gbfile.h" // for gbfgetstr, gbfclose, gbfopen, gbfile -#include "grtcirc.h" // for RAD, gcdist, radtomiles -#include "jeeps/gpsmath.h" // for GPS_Math_WGS84_To_UTM_EN, GPS_Lookup_Datum_Index, GPS_Math_Known_Datum_To_WGS84_M, GPS_Math_UTM_EN_To_Known_Datum, GPS_Math_WGS84_To_Known_Datum_M, GPS_Math_WGS84_To_UKOSMap_M -#include "jeeps/gpsport.h" // for int32 -#include "session.h" // for session_t -#include "src/core/datetime.h" // for DateTime -#include "src/core/logging.h" // for Warning, Fatal -#include "src/core/optional.h" // for optional -#include "src/core/textstream.h" -#include "strptime.h" // for strptime +#include "csv_util.h" // for csv_stringtrim, dec_to_human, csv_stringclean, human_to_dec, ddmmdir_to_degrees, dec_to_intdeg, decdir_to_dec, intdeg_to_dec, csv_linesplit +#include "formspec.h" // for FormatSpecificDataList +#include "garmin_fs.h" // for garmin_fs_t, garmin_fs_alloc +#include "gbfile.h" // for gbfgetstr, gbfclose, gbfopen, gbfile +#include "grtcirc.h" // for RAD, gcdist, radtomiles +#include "jeeps/gpsmath.h" // for GPS_Math_WGS84_To_UTM_EN, GPS_Lookup_Datum_Index, GPS_Math_Known_Datum_To_WGS84_M, GPS_Math_UTM_EN_To_Known_Datum, GPS_Math_WGS84_To_Known_Datum_M, GPS_Math_WGS84_To_UKOSMap_M +#include "jeeps/gpsport.h" // for int32 +#include "session.h" // for session_t +#include "src/core/datetime.h" // for DateTime +#include "src/core/logging.h" // for FatalMsg +#include "src/core/optional.h" // for optional +#include "src/core/textstream.h" // for TextStream +#include "strptime.h" // for strptime #include "xcsv.h" @@ -163,7 +163,7 @@ enum xcsv_token { XT_YYYYMMDD_TIME }; -#include "xcsv_tokens.gperf" // for Perfect_Hash, xt_mapping +#include "xcsv_tokens.gperf" // for Perfect_Hash, xt_mapping /* a table of config file constants mapped to chars */ const XcsvStyle::char_map_t XcsvStyle::xcsv_char_table[] = { @@ -1659,7 +1659,7 @@ XcsvStyle::xcsv_parse_style_line(XcsvStyle* style, QString line) } // Separate op and tokens. - int sep = line.indexOf(QRegExp("\\s+")); + int sep = line.indexOf(QRegularExpression(R"(\s+)")); // the first token is the operation, e.g. "IFIELD" QString op = line.mid(0, sep).trimmed().toUpper(); -- 2.30.2